package com.zjj.filmcommentapi.controller;

import com.zjj.filmcommentapi.utils.FileUtil;
import com.zjj.filmcommentapi.utils.PropertiesUtil;
import com.zjj.filmcommentapi.utils.Result;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(value = "公用接口", tags = "User用户相关")
@RestController
@RequestMapping("/base")
public class BaseController {
    public Result uploadImg(@RequestParam("file") MultipartFile file) {
        String contentType = file.getContentType(); // 图片文件类型
        String fileName = file.getOriginalFilename(); // 图片名字
        String filePath = PropertiesUtil.getProp("localImgFile");
        try {
            FileUtil.uploadFile(file.getBytes(), filePath, fileName);
        } catch (Exception e) {
            return  Result.error("上传图片异常",500);
        }
        return  Result.success("上传成功",200,filePath);
    }
}
